from __future__ import annotations

import os
from typing import Optional
import redis


class RedisPool:
    def __init__(self, url: Optional[str] = None, max_connections: int = 20, timeout: int = 5) -> None:
        self._url = url or os.getenv("REDIS_URL", "redis://localhost:6379/0")
        self._pool = redis.ConnectionPool.from_url(self._url, max_connections=max_connections, socket_timeout=timeout)

    def get_client(self) -> redis.Redis:
        return redis.Redis(connection_pool=self._pool)


